# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Kevin Daudt <kdaudt@alpinelinux.org>
pkgname=mlt
pkgver=7.8.0
pkgrel=0
pkgdesc="MLT Multimedia Framework"
url="https://www.mltframework.org/"
arch="all"
license="GPL-2.0-or-later AND LGPL-2.1-or-later AND GPL-3.0-or-later"
makedepends="
	bsd-compat-headers
	chrpath
	cmake
	ffmpeg-dev
	fftw-dev
	frei0r-plugins-dev
	gtk+2.0-dev
	jack-dev
	libexif-dev
	libsamplerate-dev
	libvorbis-dev
	libxml2-dev
	python3-dev
	qt5-qtbase-dev
	qt5-qtsvg-dev
	samurai
	sdl2-dev
	sdl_image-dev
	sox-dev
	swig
	vidstab-dev
	"
options="!check" # todo
checkdepends="py3-pykwalify"
subpackages="$pkgname-dev $pkgname-doc py3-$pkgname:py3"
source="https://github.com/mltframework/mlt/archive/v$pkgver/mlt-v$pkgver.tar.gz
	musl-locale.patch
	"

case $CARCH in
ppc64le|s390x)
	_opencv=OFF
	;;
*)
	makedepends="$makedepends opencv-dev"
	_opencv=ON
	;;
esac

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_TESTING=OFF \
		-DMOD_OPENCV=$_opencv \
		-DMOD_MOVIT=OFF \
		-DMOD_PLUS=OFF \
		-DMOD_RTAUDIO=OFF \
		-DMOD_RUBBERBAND=OFF \
		-DSWIG_PYTHON=ON
	cmake --build build
}

package() {
	cd build

	# removing undesired rpath
	scanelf -BRF '%r' . | awk '$1 != "-" { print $2 }' | xargs chrpath -d
	DESTDIR="$pkgdir" cmake --install .
}

py3() {
	pkgdesc="$pkgdesc (Python bindings)"
	depends="python3"

	pythonpath=$(python3 -c "from sysconfig import get_path; print(get_path('platlib'))")

	amove "${pythonpath#/*}"
}

sha512sums="
da24e59a8fab719eb5352fd3583578938e7f2161f022747e476fe817746ea4c44b8e4319d1b7fefcf075087c255664efdbed1ce81dd22904b68335b5b218f7b2  mlt-v7.8.0.tar.gz
dfa4c192ce6121a3c86141c46a08eaf6cd6bd81c120786bdb1ef564bf7878dcb44031280b34609048409c3d09e8c0e1bd430dae1fe777ef030daf09b1dfd90a3  musl-locale.patch
"
